import Mock from "mockjs";
import AccountApi from "@/mocks/account";
import AdminApi from "@/mocks/admin";
// 修复在使用 MockJS 情况下，设置 withCredentials = true，且未被拦截的跨域请求丢失 Cookies 的问题
// https://github.com/nuysoft/Mock/issues/300
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send;
Mock.XHR.prototype.send = function() {
  if (this.custom.xhr) {
    this.custom.xhr.withCredentials = this.withCredentials || false;
  }
  this.proxy_send(...arguments);
};

//账号相关
Mock.mock(/\/info/, "get", AccountApi.fetchInfo);
Mock.mock(/\/login/, "post", AccountApi.login);
Mock.mock(/\/logout/, "post", AccountApi.logout);
Mock.mock(/\/change-pwd/, "post", AccountApi.changePwd);

//管理员相关
Mock.mock(/\/admin\/list/, "get", AdminApi.fetchList);
Mock.mock(/\/admin\/setStatus/, "post", AdminApi.setStatus);
Mock.mock(/\/admin\/detail/, "get", AdminApi.fetchDetail);
Mock.mock(/\/admin\/store/, "post", AdminApi.store);
Mock.mock(/\/admin\/save/, "post", AdminApi.save);

export default Mock;
